#ifndef CONNECTION_H
#define CONNECTION_H

#include <QThread>
#include <QObject>
#include <QTcpSocket>
#include <QIODevice>

class Connection : public QObject
{
    Q_OBJECT
    Q_PROPERTY(QTcpSocket* socket READ socket NOTIFY connected)
public:
    explicit Connection(QObject *parent = 0);
    Connection(const Connection &connection);

    bool connect(const QString address, const quint16 port);
    void disconnect();
    void send(const QString bytes);
    void send(const QByteArray bytes);
    const QByteArray receive(const int lenght);
    const QString receiveLine();

    bool isConnected() const;
    QTcpSocket *socket() const;

signals:
    void connected();
    void disconnecting();
    void lineReceived(const QString line);
    void dataReceived(const QByteArray data);
    void lineSended(const QString line);
    void dataSended(const QByteArray data);
    void dataReceiving(const qreal progress);

public slots:

private:
    QTcpSocket* _socket;
    
};

#endif // CONNECTION_H
